﻿using Aga.Diagrams.TestExtend.Flowchart;
using AIStudio.Wpf.OA_Manage.Models;
using AIStudio.Wpf.PetaPoco;
using AIStudio.Wpf.Service.ITempService;
using CommonServiceLocator;
using Prism.Mvvm;
using System.Collections.Generic;

namespace AIStudio.Wpf.OA_Manage.ViewModels
{
    public class OA_DefFormTreeEditViewModel : BindableBase
    {
        private string _title;
        public string Title
        {
            get { return _title; }
            set
            {
                if (_title != value)
                {
                    SetProperty(ref _title, value);
                }
            }
        }

        private List<Base_RoleEasy> _roles;
        public List<Base_RoleEasy> Roles
        {
            get { return _roles; }
            set
            {
                if (_roles != value)
                {
                    SetProperty(ref _roles, value);
                }
            }
        }


        private List<Base_UserEasy> _users;
        public List<Base_UserEasy> Users
        {
            get { return _users; }
            set
            {
                if (_users != value)
                {
                    SetProperty(ref _users, value);
                }
            }
        }

        private FlowchartModel _flowchartModel;
        public FlowchartModel FlowchartModel
        {
            get { return _flowchartModel; }
            set
            {
                if (_flowchartModel != value)
                {
                    SetProperty(ref _flowchartModel, value);
                }
            }
        }

        protected IUserData _userData { get; }

        public OA_DefFormTreeEditViewModel(string workflowJSON, string title = "查看流程图") 
        {
            _userData = ServiceLocator.Current.GetInstance<IUserData>();

            var OAData = Newtonsoft.Json.JsonConvert.DeserializeObject<OAData>(workflowJSON);
            FlowchartModel model = new FlowchartModel();
            FlowChartHelper.G6ToFlowChart(OAData, model);
            FlowchartModel = model;
            Title = title;
            GetRoles();
            GetUsers();
        }

        private async void GetRoles()
        {
            Roles = await _userData.GetAllRole();
        }

        private async void GetUsers()
        {
            Users = await _userData.GetAllUser();
        }
    }
}
